package love.yuanmengrobot.wuziqi.UIldq;
/*
 *   @Studio:CHJY · 源梦科技
 *   @Author:Lishao
 *   @Ide:IntelliJ IDEA
 *   @Creation time:2021/5/11 18:53
 */

import love.yuanmengrobot.wuziqi.Util.Point;

import java.awt.*;
import java.util.HashMap;
import java.util.List;

public class judge_score {

    Color[] colorsum=new Color[7];

    public HashMap<String, Integer> judge(List<Point> points ){
        colorsum[0]=new Color(254,0,0);
        colorsum[1]=new Color(253,166,0);
        colorsum[2]=new Color(255,255,1);
        colorsum[3]=new Color(0,128,1);
        colorsum[4]=new Color(63,224,208);
        colorsum[5]=new Color(64,0,151);
        colorsum[6]=new Color(148,0,212);

//        System.out.println("打印尝试开始");
//        for(Point p:points){
//            System.out.println("打印尝试"+p.getX() + p.getY() + p.getColor());
//        }

        int[][] Board=new int[15][15];
        String[] colorname={"红色","橙色","金色","绿色","蓝色","靛色","紫色"};
        HashMap<String,Integer> map=new HashMap<String,Integer>();
        for (String AA:colorname){
            map.put(AA,0);        //循环初始化每种颜色的分数都为0
        }
        for (int j=0;j<points.size();j++){
            for(int i=0;i<colorsum.length;i++){  //使用该循环检测一下该点的颜色
                if (points.get(j).getColor().toString().equals(colorsum[i].toString())){
                    Board[points.get(j).getX()][points.get(j).getY()]=i+1;
                    break;       //当找到该点的颜色就跳出循环
                }
            }
        }
        for (int a=0;a<15;a++){
            for (int b=0;b<15;b++) {
                int c = 1;
                int sumscore = 0;
                if (Board[a][b] > 0 && Board[a][b] < 8) {           //有颜色的棋子进行寻找
                    if((b==0)||(b!=14&&Board[a][b]!=Board[a][b-1])) {
                        while ((b+c) <=14&&Board[a][b] == Board[a][b+c]) {
                            c++;                                       //判断右边是否有相同颜色的棋子，并计算右边的积分
                        }
                        if (c <= 5)
                            sumscore = sumscore + c * (c - 1);
                        if (c > 5)
                            sumscore = sumscore + 20;
                    }
                    c = 1;
                    if((a==0||b==0)||(a!=14&&b!=14&&Board[a][b]!=Board[a-1][b-1])) {
                        while ((a + c) <=14 && (b + c) <=14&&Board[a][b] == Board[a + c][b + c] ) {
                            c++;                                      //判断右下角是否有相同颜色的棋子，并计算右下角的积分
                        }
                        if (c <= 5)
                            sumscore = sumscore + c * (c - 1);
                        if (c > 5)
                            sumscore = sumscore + 20;
                    }
                    c=1;
                    if((a==0)||(a!=14&&Board[a][b]!=Board[a-1][b])) {
                        while ((a+c) <=14&&Board[a][b] == Board[a+c][b] ){
                            c++;                                      //判断正下方是否有相同颜色的棋子，并计算正下方的积分
                        }
                        if (c <= 5)
                            sumscore = sumscore + c * (c - 1);
                        if (c > 5)
                            sumscore = sumscore + 20;
                    }
                    c=1;
                    if ((a==0||b==14)||(a!=14&&b!=0&&Board[a][b]!=Board[a-1][b+1])) {
                        while ((a + c) <=14 && (b - c) >=0&&Board[a][b] == Board[a+c][b-c]) {
                            c++;                                      //判断左下角是否有相同颜色的棋子，并计算左下角的积分
                        }
                        if (c <= 5)
                            sumscore = sumscore + c * (c - 1);
                        if (c > 5)
                            sumscore = sumscore + 20;
                    }
                    int lastscore=map.get(colorname[Board[a][b]-1]);
                    map.put(colorname[Board[a][b] - 1], sumscore+lastscore);

                }
            }
        }
        return map;





    }
}
